var t = require("../../../@babel/runtime/helpers/typeof");

Component({
    properties: {
        src: {
            value: "",
            type: String
        },
        duration: {
            value: 0,
            type: String
        }
    },
    data: {
        songStop: !1,
        innerAudioContext: null,
        slmin: "00:00",
        audio_duration: "00:00",
        currentTime: 0,
        valueSlmin: 0,
        draging: !1
    },
    lifetimes: {
        attached: function() {
            this.init();
        },
        moved: function() {},
        detached: function() {
            this.data.innerAudioContext && this.data.innerAudioContext.destroy();
        }
    },
    methods: {
        init: function() {
            var t = this, n = this;
            this.data.innerAudioContext = wx.createInnerAudioContext(), this.data.innerAudioContext.src = this.data.src, 
            this.data.src ? (this.data.innerAudioContext.onCanplay(function() {
                console.log("音频进入可以播放状态========================", t.data.duration, t.data.innerAudioContext.duration), 
                setTimeout(function() {
                    var n = t.data.innerAudioContext.duration == 1 / 0 && t.data.innerAudioContext.duration ? t.data.duration : t.data.innerAudioContext.duration, a = parseInt(n);
                    t.setData({
                        audio_duration: a ? t.realFormatSecond(a) : "---",
                        draging: !1,
                        slmin: "0:00:00"
                    });
                }, 200);
            }), this.data.innerAudioContext.onPlay(function() {
                console.log("开始播放"), t.setData({
                    songStop: !0
                });
            }), this.data.innerAudioContext.onTimeUpdate(function() {
                if (!t.data.draging && t.data.innerAudioContext.currentTime) {
                    var a = t.data.innerAudioContext.duration == 1 / 0 && t.data.innerAudioContext.duration ? t.data.duration : t.data.innerAudioContext.duration, i = parseInt(t.data.innerAudioContext.currentTime) / parseInt(a) * 100, e = t.realFormatSecond(a);
                    if (!t.data.currentTime || t.data.currentTime != parseInt(t.data.innerAudioContext.currentTime)) {
                        t.data.currentTime = parseInt(t.data.innerAudioContext.currentTime);
                        var o = parseInt(i);
                        n.setData({
                            valueSlmin: o,
                            audio_duration: e,
                            slmin: t.realFormatSecond(parseInt(t.data.innerAudioContext.currentTime))
                        });
                    }
                }
            }), this.data.innerAudioContext.onError(function(n) {
                wx.showToast({
                    title: "播放错误",
                    icon: "none"
                }), t.setData({
                    songStop: !1
                });
            }), this.data.innerAudioContext.onEnded(function(n) {
                console.log("结束播放"), t.setData({
                    songStop: !1,
                    valueSlmin: 0,
                    slmin: "0:00:00",
                    draging: !1
                });
            }), this.data.innerAudioContext.onPause(function() {
                t.setData({
                    songStop: !1
                });
            })) : wx.showToast({
                title: "音频链接出错！",
                icon: "error"
            });
        },
        sildein: function(t) {
            var n = t.detail / 100, a = (this.data.innerAudioContext.duration == 1 / 0 && this.data.innerAudioContext.duration ? this.data.duration : this.data.innerAudioContext.duration) * n;
            this.data.innerAudioContext.seek(a);
        },
        realFormatSecond: function(n) {
            var a = t(n);
            if ("number" === a || "string" === a) {
                n = parseInt(n);
                var i = Math.floor(n / 3600);
                n -= 3600 * i;
                var e = Math.floor(n / 60);
                return n -= 60 * e, isNaN(n) ? "---" : i + ":" + ("0" + e).slice(-2) + ":" + ("0" + n).slice(-2);
            }
            return "0:00:00";
        },
        playMusic: function() {
            this.data.innerAudioContext.play();
        },
        pauseMusic: function() {
            this.data.innerAudioContext.pause();
        },
        startDrag: function() {
            this.data.draging = !0;
        },
        endDrag: function() {
            this.data.draging = !1;
        }
    }
});